package com.gitbl.webchat.server;

import com.alibaba.dubbo.config.RegistryConfig;
import com.gitbl.webchat.db.DbUtils;
import com.gitbl.webchat.db.bean.UserBean;
import com.gitbl.webchat.db.mapper.UserMapper;
import com.gitbl.webchat.message.User;


import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Assert;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.ClassPathXmlApplicationContext;
//import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;


import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.Properties;
import groovyjarjarcommonscli.*;
@SpringBootApplication
public class Application {

    public static void main(String[] args) throws IOException, ParseException {
        Options options = new Options();
        @SuppressWarnings("static-access")
        Option property = OptionBuilder.withArgName("property=value")
                .hasArgs(2)
                .withValueSeparator()
                .withDescription("use value for given property(property=value) \neg: -Dzk=192.168.10.144:2181,192.168.10.144:2082 -Dbindport=20881" +
                        "\\\n-Ddbhost=localhost:3306" +
                        "\\\n-Ddbuser=sa" +
                        "\\\n-Ddbpwd=sa")
                .create("D");
        property.setRequired(true);
        options.addOption(property);
        // print usage
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp( "webchat-provider-user", options );
        System.out.println();
        // create the command line parser
        CommandLineParser parser = new PosixParser();
        if(args.length>0) {
            CommandLine cmd = parser.parse(options, args);
            Properties ps = cmd.getOptionProperties("D");

            for (Object p : ps.keySet()) {
                System.out.println(p.toString() + "=" + ps.getProperty(p.toString()));
                System.setProperty(p.toString(), ps.getProperty(p.toString()));
            }
        }


        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:dubbo-provider-user.xml");

        context.start();
        //SpringApplication.run(App.class, args);
        while (true){
            if(System.in.read()=='q'){
                System.out.println("exit");
                context.stop();
                break;
            }
        }

    }





}
